package com.gxy.learn.mybatisplus.web;

import com.gxy.learn.mybatisplus.common.Result;
import com.gxy.learn.mybatisplus.service.SysUserService;
import com.gxy.learn.mybatisplus.vo.ListPageReqVO;
import com.gxy.learn.mybatisplus.vo.SysUserSaveVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * 增删改查 分页、管理查询demo
 *
 * @author: Gao xueyong
 * Create at: 2022/02/17 下午14:18
 */
@Validated
@Slf4j
@RequestMapping("/sys/user")
@RestController
public class UserController {

    @Autowired
    private SysUserService service;

    @PostMapping(value = "/listPage")
    public Result listPage(@Valid @RequestBody ListPageReqVO reqVO) {
        return Result.success(service.listPage(reqVO));
    }

    @GetMapping(value = "/users")
    public Result users(@RequestParam(value = "companyId") @NotBlank(message = "companyId不能为空！") String companyId) {
        return Result.success(service.users(companyId));
    }

    @GetMapping(value = "/info")
    public Result info(@RequestParam(value = "id") @NotBlank(message = "id不能为空！") String id) {
        return Result.success(service.info(id));
    }

    @PostMapping(value = "/save")
    public Result save(@Valid @RequestBody SysUserSaveVO saveVO) {
        service.save(saveVO);
        return Result.success("操作成功！");
    }

    @DeleteMapping(value = "/del")
    public Result del(@RequestParam(value = "id") @NotBlank(message = "id不能为空！") String id) {
        service.removeById(id);
        return Result.success();
    }

    @GetMapping(value = "/test")
    public Result test() {
        service.listTest();
        return Result.success();
    }

}
